using LuaInterface;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ReturnDrag : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        
    }

    
    public float minDragDis = 100;
    public float minDifDis = 100;
    public float minSpeed = 1.5f;

    float downX;
    float upX;
    double downTime;
    double upTime;

    bool isReturn = false;

    void iosReturn()
    {
        if (Input.touchCount == 1)
        {

            if (Input.touches[0].phase == TouchPhase.Began)
            {


                downX = Input.mousePosition.x;
                downTime = DateTime.Now.TimeOfDay.TotalMilliseconds;
               // Debug.LogError("x" + downX);
                if ((downX < minDifDis) || (downX > Screen.width - minDifDis))
                {
                    isReturn = true;
                }

            }
            if (Input.touches[0].phase == TouchPhase.Ended)
            {
                if (!isReturn)
                {
                    return;
                }

                upTime = DateTime.Now.TimeOfDay.TotalMilliseconds;
                upX = Input.mousePosition.x;

                double speed = (upX - downX) / (upTime - downTime);
                float dis = (upX - downX);
                if (Math.Abs(dis) > minDragDis && Math.Abs(speed) > minSpeed)
                {
                    if (LuaMgr.GetMainState() != null)
                    {
                        LuaFunction func = LuaMgr.GetMainState().GetFunction("QuitTool.QuitTool.IosReturn");
                        if (func != null)
                        {
                            func.BeginPCall();
                            func.PCall();
                            func.EndPCall();
                            func.Dispose();
                        }
                    }
                }
            }
        }
        }
        // Update is called once per frame
        void Update()
    {
#if UNITY_IPHONE
        iosReturn();
#endif
        
    }
}
